//
//  SinaStatusModel.swift
//  weibo
//
//  Created by sirius on 16/1/5.
//  Copyright © 2016年 sirius. All rights reserved.
//

import UIKit

class SinaStatusModel: NSObject {
    
    /// created_at	string	微博创建时间
    var created_at: String?
    ///id	int64	微博ID
    var id: Int = 0
    ///text	string	微博信息内容
    var text: String?
    ///source	string	微博来源
    var source: String?
    //微博作者的用户信息字段
    var user: SinaUserModel?
    
    //reposts_count
    var reposts_count: Int = 0
    //comments_count
    var comments_count: Int = 0
    //attitides_count
    var attitudes_count: Int = 0
    
    ///retweeted_status object
    var retweeted_status: SinaStatusModel?
    
    //配图的模型
    var pic_urls: [SinaPictureModel]?
    
    
    
    init(dic: [String: AnyObject]) {
        
        super.init()
        
        setValuesForKeysWithDictionary(dic)
        if let userDic = dic["user"] as? [String: AnyObject]{
            //获取字典后，字典转模型
            user = SinaUserModel(dic: userDic)
        }
        
    
    //读取转发微博的信息
    if let retweetDic = dic["retweeted_status"] as? [String:AnyObject] {
        retweeted_status = SinaStatusModel(dic: retweetDic)
    }
        if let pics = dic["pic_urls"] as? [[String:AnyObject]]{
            //给数组初始化
            pic_urls = [SinaPictureModel]()
            //进行遍历
            for pic in pics {
                let picModel = SinaPictureModel(dic: pic)
                //添加到数组中
                pic_urls?.append(picModel)
            }
        }
    }
    //确保不崩溃
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
}
